//
//  AXFFeebackController.h
//  AXFEightGroup
//
//  Created by hgj on 2016/12/28.
//  Copyright © 2016年 ya. All rights reserved.
//

#import "AXFMyOredrController.h"
#import "AXFOrderViewModel.h"
#import "AXFOrderCell.h"
#import "AXFOrderCellViewModel.h"
#import "AXFOrderDetailViewController.h"

static NSString *orderCellId = @"orderCellId";

@interface AXFMyOredrController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)AXFOrderViewModel *orderViewModel;

@end

@implementation AXFMyOredrController


- (AXFOrderViewModel *)orderViewModel {
    
    if (!_orderViewModel) {
        
        _orderViewModel = [[AXFOrderViewModel alloc]init];
    }
    return _orderViewModel;
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.title = @"我的订单";
    
    [self setNav];
    
    [self setupUI];
    
}

#pragma mark
#pragma mark - 设置导航栏按钮
- (void)setNav
{
    // 左上角返回按钮
    UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self.navigationController action:@selector(popViewControllerAnimated:)];
    
    [[UINavigationBar appearance] setTintColor:[UIColor grayColor]];
    
    // 设置左上角的返回按钮
    self.navigationItem.leftBarButtonItem = item;
}

- (void)setupUI
{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [self.orderViewModel loadData:^(BOOL isSuccess) {
        
//        NSLog(@"%@",self.orderViewModel.viewmodelArray[0].model);
        [tableView reloadData];
        
    }];
    
    
    [tableView registerNib:[UINib nibWithNibName:@"AXFOrderCell" bundle:nil] forCellReuseIdentifier:orderCellId];
    
    tableView.delegate = self;
    
    tableView.dataSource = self;
    
    //预估行高
    tableView.estimatedRowHeight = 250;
    

}

#pragma mark - UITableViewDataSource -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.orderViewModel.viewmodelArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AXFOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:orderCellId forIndexPath:indexPath];
    
    cell.viewModel = self.orderViewModel.viewmodelArray[indexPath.section];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.1;
}

#pragma mark - UITableViewDelegate -
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    AXFOrderDetailViewController *vc = [[AXFOrderDetailViewController alloc]init];
    
    vc.statusModelList = self.orderViewModel.viewmodelArray[indexPath.section].status_timeline;
    
    vc.detailModel = self.orderViewModel.viewmodelArray[indexPath.section];
    
    [self.navigationController pushViewController:vc animated:YES];

}



@end
